package com.example.springmvcdemo;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/response")
@Controller
public class ResponseController {
    @RequestMapping("/index")
    public String index(){
        return "/index.html";
    }

    @ResponseBody
    @RequestMapping("/returnData")
    public String returnData() {
        System.out.println("returnData");
        return "returnData";
    }

    @ResponseBody
    @RequestMapping("/returnHTML")
    public String returnHTML() {
        System.out.println("returnHTML");
        return "<h1>我是一个页面</h1>";
    }

    @ResponseBody
    @RequestMapping("/returnJson")
    public UserInfo returnJson() {
        UserInfo userInfo = new UserInfo("zhangsan","123456",22);
        System.out.println("userInfo "+userInfo);
        return userInfo;
    }

    @ResponseBody
    @RequestMapping("/setStatus")
    public String setStatus(HttpServletResponse response) {
        response.setStatus(401);
        System.out.println("set status successfully");
        return "set status successfully";
    }
}
